package kr.co.redcircle.oauth.authorize;

import java.util.Hashtable;

import javax.servlet.http.HttpSession;

import kr.co.redcircle.service.oAuth.internal.InternalDataManager;
import kr.co.redcircle.service.oAuth.model.SNSDefaultParameters;
import kr.co.redcircle.service.oAuth.model.SNSModel;
import net.sf.json.JSONObject;

public class SessionManager {
	
	private static final String TEMPLATE_INFO = "template_info";
	private static final String MASSAGE = "message";
	private HttpSession session;
	private String result;
	private Hashtable<String, SNSModel> modelCollection = new Hashtable<String, SNSModel>();
	private String sessionId;
	
	public SessionManager(HttpSession session) {
		this.session = session;
		sessionId = this.session.getId();
	}

	public boolean send(){
	
		return false;
	}
	
	public void setAuth(String result){
		this.result = result;
	}

	public void invoke(String[] message){
		System.out.println("modelCollection.size() : " + this.modelCollection.size());
		String command_id = "post.thread";
		
		// save user data to internal data storage
		InternalDataManager.getInstance(sessionId);
		
		
		for (SNSModel model : modelCollection.values()){
			SNSDefaultParameters params = new SNSDefaultParameters();
			params.put(MASSAGE, message[0]);
			model.put(TEMPLATE_INFO, message[1]);
			model.invoke(command_id, params);
		}
		
	}
	
	@Override
	public String toString() {
		return super.toString();
	}
	
	public void addModel(SNSModel model){		
		this.modelCollection.put(model.getId(), model);
	}
	
	public SNSModel getModel(String snsId){
		return this.modelCollection.get(snsId);
	}
}
